package com.itheima.user.controller;

import com.itheima.entity.dto.LikeDto;
import com.itheima.entity.vo.Result;
import com.itheima.user.service.LikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author :wujunjie
 * createTime :2022-12-15 20:21
 * description :
 */
@RestController
@RequestMapping("/userService/like")
public class LikeController {
    @Autowired
    private LikeService likeService;

    @PostMapping
    public Result insertLike(@RequestBody LikeDto likeDto){
          Boolean insert = likeService.insertLike(likeDto);
        if (insert){
            return Result.success();
        }
        return Result.error();
    }

    @DeleteMapping("{likeId}")
    public Result deleteLike(@PathVariable String likeId){
        Boolean delete = likeService.deleteLike(likeId);
        if (delete){
            return Result.success();
        }
        return Result.error();
    }

    @GetMapping
    public Result selectPage(@RequestParam(name = "name",required = false) String name,
                            @RequestParam(name = "type",defaultValue = "1") Integer type,
                            @RequestParam(name="page",defaultValue = "1") Integer page,
                            @RequestParam(name="pageSize",defaultValue = "10") Integer pageSize){

        return Result.success(likeService.selectPage(name,type,page,pageSize));

    }

}
